package is.ru.honn.rupin.data;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import is.ru.honn.rupin.domain.Board;
import is.ru.honn.rupin.domain.Pin;
import is.ru.honn.rupin.domain.User;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;

/**
 * Created with IntelliJ IDEA.
 * User: gmatt
 * Date: 20.10.2012
 * Time: 12:50
 *
 * Maps the column values to the appropriate properties of a Pin instance
 */
public class PinRowMapper implements ParameterizedRowMapper<Pin> {
    /**
     * @param rs The result set to map (1 or more rows of Pins)
     * @param rowNum The number of the row to map
     * @return The appropriate Pin instance
     * @throws SQLException
     */
    public Pin mapRow(ResultSet rs, int rowNum) throws SQLException {
        Pin pin = new Pin(rs.getString(2),
                          rs.getString(1),
                          rs.getString(3));
        pin.setCreated(rs.getDate(6));
        pin.setBoard(new Board(rs.getString(4), null));
        pin.setCreator(new User(rs.getString(5), null, null, null, null, null));
        return pin;
    }
}
